package org.bedracket.pgeg.init;

import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraftforge.common.extensions.IForgeMenuType;
import net.minecraftforge.network.IContainerFactory;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.bedracket.pgeg.PGEGMod;
import org.bedracket.pgeg.screen.TestMenu;

import java.util.Locale;

public class ModMenuTypes {
    public static final DeferredRegister<MenuType<?>> MENU_TYPES =
            DeferredRegister.create(ForgeRegistries.MENU_TYPES, PGEGMod.MOD_ID);

    public static final RegistryObject<MenuType<TestMenu>> TEST_MENU =
            registry("test_menu", TestMenu::new);

    /**
     * Used for registry menu
     *
     * @param name Menus' registry name
     * @param factory menuTypeSupplier
     * @param <T> sth extends AbstractContainerMenu
     * @return RegistryObject<MenuType>
     */
    private static <T extends AbstractContainerMenu> RegistryObject<MenuType<T>> registry(String name, IContainerFactory<T> factory) {
        return MENU_TYPES.register(name.toLowerCase(Locale.ROOT), () -> IForgeMenuType.create(factory));
    }
}
